<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <title>添加医院</title>
  <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <link rel="stylesheet" href="../../static/css/style.css" th:href="@{/css/style.css}"/>
  <script>
    function encodeImageFileAsURL(element) {
      var file = element.files[0];
      var reader = new FileReader();
      reader.onloadend = function() {
        document.getElementById('encodedPicture').value = reader.result;
      }
      reader.readAsDataURL(file);
    }
  </script>
</head>
<body>
<div th:replace="~{common/layout :: header}"></div>
<div th:replace="~{common/layout :: sidebar}"></div>
<div class="container mt-5">
  <h1 class="mb-4">添加医院</h1>
  <form action="#" th:action="@{/hospitals/add}" th:object="${hospital}" method="post" class="form-horizontal">
    <div class="form-group">
      <label class="control-label col-sm-2">名称:</label>
      <div class="col-sm-10">
        <input type="text" th:field="*{name}" class="form-control" required/>
      </div>
    </div>
    <div class="form-group">
      <label class="control-label col-sm-2">图片:</label>
      <div class="col-sm-10">
        <input type="file" class="form-control" accept="image/*" onchange="encodeImageFileAsURL(this)" />
        <input type="hidden" id="encodedPicture" th:field="*{picture}" />
      </div>
    </div>
    <div class="form-group">
      <label class="control-label col-sm-2">电话:</label>
      <div class="col-sm-10">
        <input type="text" th:field="*{telephone}" class="form-control" required/>
      </div>
    </div>
    <div class="form-group">
      <label class="control-label col-sm-2">地址:</label>
      <div class="col-sm-10">
        <input type="text" th:field="*{address}" class="form-control" required/>
      </div>
    </div>
    <div class="form-group">
      <label class="control-label col-sm-2">营业时间:</label>
      <div class="col-sm-10">
        <input type="text" th:field="*{businessHours}" class="form-control" required/>
      </div>
    </div>
    <div class="form-group">
      <label class="control-label col-sm-2">截止日期:</label>
      <div class="col-sm-10">
        <input type="date" th:field="*{deadline}" class="form-control" required/>
      </div>
    </div>
    <div class="form-group">
      <label class="control-label col-sm-2">规则:</label>
      <div class="col-sm-10">
        <input type="text" th:field="*{rule}" class="form-control" required/>
      </div>
    </div>
    <div class="form-group">
      <label class="control-label col-sm-2">状态:</label>
      <div class="col-sm-10">
        <select th:field="*{state}" class="form-control" required>
          <option value="1">Active</option>
          <option value="0">Inactive</option>
        </select>
      </div>
    </div>
    <div class="form-group">
      <div class="col-sm-offset-2 col-sm-10">
        <button type="submit" class="btn btn-primary">提交</button>
      </div>
    </div>
  </form>
  <a href="/hospitals" class="btn btn-default">返回医院列表</a>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>